//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Configuration.Design
{
	/// <summary>
	/// This class adds Data Query commands to the context menus of the nodes in the
	/// Query Application Block node hierarchy.
	/// </summary>
	sealed class DataQueryCommandRegistrar : CommandRegistrar
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="T:DataQueryCommandRegistrar"/> class.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public DataQueryCommandRegistrar(IServiceProvider serviceProvider) : base(serviceProvider) 
    {
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Register the commands.
		/// </summary>
		public override void Register ()
    {
			AddDataCommandCommand();
			AddDefaultCommands(typeof(DataCommandNode));

			AddDataQueryCommand();
			AddDefaultCommands(typeof(DataQueryNode));

			AddDataParameterCommand();
			AddDefaultCommands(typeof(DataParameterNode));

			AddDataSetParameterCommand();
			AddDefaultCommands(typeof(DataSetParameterNode));
		}
		#endregion

		#region Private Methods
		private void AddDataCommandCommand()
		{
			AddMultipleChildNodeCommand(InternalResources.DataCommandUICommandText,
																	InternalResources.DataCommandUICommandLongText,
																	typeof(DataCommandNode),
																	typeof(CommandCollectionNode));
		}

		private void AddDataQueryCommand()
		{
			ConfigurationUICommand command = ConfigurationUICommand.CreateMultipleUICommand(ServiceProvider,
																																											InternalResources.DataQueryUICommandText,
																																											InternalResources.DataQueryUICommandLongText,
																																											new AddDataQueryNodeCommand(ServiceProvider),
																																											typeof(DataQueryNode));
			AddUICommand(command, typeof(QueryCollectionNode));
			command.Dispose();
		}

		private void AddDataParameterCommand()
		{
			AddMultipleChildNodeCommand(InternalResources.DataParameterUICommandText,
																	InternalResources.DataParameterUICommandLongText,
																	typeof(DataParameterNode),
																	typeof(ParameterSetNode));
		}

		private void AddDataSetParameterCommand()
		{
			AddMultipleChildNodeCommand(InternalResources.DataSetParameterUICommandText,
																	InternalResources.DataSetParameterUICommandLongText,
																	typeof(DataSetParameterNode),
																	typeof(ParameterSetNode));
		}
		#endregion
	}
}
